<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0,user-scalable=no,minimal-ui">
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="icon" href="../img/asset-favico.ico">
    <title>编辑信息</title>
    <link rel="stylesheet" href="../css/page-health-orderInfo.css"/>
    <link rel="stylesheet" href="../plugins/elementui/index.css"/>
    <script src="../plugins/jquery/dist/jquery.min.js"></script>
    <script src="../plugins/healthmobile.js"></script>
    <script src="../plugins/datapicker/datePicker.js"></script>
    <script src="../plugins/vue/vue.js"></script>
    <script src="../plugins/vue/axios-0.18.0.js"></script>
    <script src="../plugins/elementui/index.js"></script>
    <script type="text/javascript" src="//api.map.baidu.com/api?v=2.0&ak=HSymSWYqoRYKGB9piZaoG8a1OjhLZdx5"></script>
</head>
<body data-spy="scroll" data-target="#myNavbar" data-offset="150">
<div id="app" class="app">
    <!-- 页面头部 -->
    <div class="top-header">
        <span class="f-left"><i class="icon-back" onclick="history.go(-1)"></i></span>
        <span class="center">传智健康</span>
        <span class="f-right"><i class="icon-more"></i></span>
    </div>
    <!-- 页面内容 -->
    <div class="contentBox">
        <div class="card">
            <div class="">
                <img v-if="setmeal.img" :src="'http://health.zlf520.cn/'+setmeal.img" width="100%"
                     height="100%"/>
            </div>
            <div class="project-text">
                <h4 class="tit">{{setmeal.name}}</h4>
                <p class="subtit">{{setmeal.remark}}</p>
                <p class="keywords">
                    <span>{{setmeal.sex == '0' ? '性别不限' : setmeal.sex == '1' ? '男':'女'}}</span>
                    <span>{{setmeal.age}}</span>
                </p>
            </div>
            <div class="project-know">
                <a href="orderNotice.html" class="link-page">
                    <i class="icon-ask-circle"><span class="path1"></span><span class="path2"></span></i>
                    <span class="word">预约须知</span>
                    <span class="arrow"><i class="icon-rit-arrow"></i></span>
                </a>
            </div>
        </div>
        <div class="form-info">
            <div class="info-title">
                <span class="name">体检人信息</span>
            </div>
            <form class="info-form">
                <div class="input-row">
                    <label>体检人</label>
                    <input v-model="orderInfo.name" type="text" class="input-clear" placeholder="请输入姓名">
                </div>
                <div class="input-row single-radio">
                    <label class="radio-title">性别</label>
                    <div class="radio-list">
                        <div class="radio">
                            <input v-model="orderInfo.sex" id="item1" type="radio" name="sex" value="1" checked>
                            <label for="item1"></label>
                            <span>男</span>
                        </div>
                        <div class="radio">
                            <input v-model="orderInfo.sex" id="item2" type="radio" name="sex" value="2">
                            <label for="item2"></label>
                            <span>女</span>
                        </div>
                    </div>
                </div>
                <div class="input-row">
                    <label>手机号</label>
                    <input v-model="orderInfo.telephone" type="text" class="input-clear" placeholder="请输入手机号">
                    <input style="font-size: x-small;" id="validateCodeButton" @click="sendValidateCode()" type="button" value="发送验证码">
                </div>
                <div class="input-row">
                    <label>验证码</label>
                    <input v-model="orderInfo.validateCode" type="text" class="input-clear" placeholder="请输入验证码">
                </div>
                <div class="input-row">
                    <label>身份证号</label>
                    <input v-model="orderInfo.idCard" type="text" class="input-clear" placeholder="请输入身份证号">
                </div>
                <div class="input-row">
                    <label>预约地址</label>
                    <el-select v-model="value" placeholder="请选择">
                        <el-option
                                v-for="item in addressList"
                                :key="item.id"
                                :label="item.ad_name"
                                :value="item.id">
                        </el-option>
                    </el-select>
                    <el-button type="primary" round icon="el-icon-location" @click="showMap()">查看地图定位</el-button>
                </div>
                <div v-show="isMap">
                    <div id="allmap" style="height:500px"></div>
                </div>
                <div class="date">
                    <label>体检日期</label>
                    <i class="icon-date" class="picktime"></i>
                    <input v-model="orderInfo.orderDate" type="text" class="picktime" readonly>
                </div>
            </form>
            <div class="box-button">
                <button @click="submitOrder()" type="button" class="btn order-btn">提交预约</button>
            </div>
        </div>
    </div>
</div>
<script>
    var vue = new Vue({
        el: '#app',
        data: {
            setmeal: {},//套餐信息
            orderInfo: {//预约信息
                setmealId: null,
                sex: '1'
            },
            isMap:false,
            addressList: [],
            address:{},
            value: ''
        },
        methods: {
            showMap(){
                this.isMap = true;
                axios.get("/address/findById/"+this.value).then(response => {
                    console.log(response.data);
                    if (response.data.flag) {
                        this.address= response.data.data;

                        // 百度地图API功能
                        var map = new BMap.Map("allmap");
                        var point = new BMap.Point(this.address.ad_jd, this.address.ad_wd);
                        map.centerAndZoom(point, 14);
                        var marker = new BMap.Marker(point);
                        map.addOverlay(marker);
                        marker.setAnimation(BMAP_ANIMATION_BOUNCE); //跳动的动画

                        map.enableScrollWheelZoom(); //启用滚轮放大缩小，默认禁用
                        map.enableContinuousZoom(); //启用地图惯性拖拽，默认禁用

                    } else {
                        this.$message.error(response.data.message);
                    }
                });
            },
            //发送验证码
            sendValidateCode() {
                //验证手机号是否符合规则
                var telephone = this.orderInfo.telephone;
                if (!checkTelephone(telephone)) {
                    this.$message.error("请输入正确的手机号");
                    return;
                }

                //倒计时60s读秒效果  $("#validateCodeButton") jquery对象 ---> DOM对象  =  jquery对象[0]  jquery对象.get(0)
                //validateCodeButton = $("#validateCodeButton")[0];
                validateCodeButton = document.getElementById("validateCodeButton");
                clock = window.setInterval(doLoop, 1000); //一秒执行一次

                //发送异步请求 , 发送短信
                var url = "/sms/sendCode?phone=" + telephone;
                axios.post(url).then(response => {
                    //提示信息
                    this.$message({
                        type: response.data.flag ? "success" : "error",
                        message: response.data.message
                    })
                })
            },
            //提交预约
            submitOrder() {
                //校验用户姓名是否输入
                if (!this.orderInfo.name) {
                    this.$message.error("请输入姓名");
                    return;
                }

                //校验手机号码是否正确
                if (!checkTelephone(this.orderInfo.telephone)) {
                    this.$message.error("请输入正确的手机号码");
                    return;
                }

                //校验身份证号码格式是否正确
                if (!checkIdCard(this.orderInfo.idCard)) {
                    this.$message.error("请输入正确的证件号码");
                    return;
                }

                //发送异步请求 ,提交预约数据
                var url = "/order/submit?addressId="+this.value;

                axios.post(url, this.orderInfo).then(response => {
                    if (response.data.flag) {
                        window.location.href = "orderSuccess.html?id=" + response.data.data;
                        return;
                    }
                    //提示错误信息
                    this.$message.error(response.data.message);
                })
            },
            findSetmealDetail() {
                //发送异步请求
                axios.get("/setmeal/" + this.setmealId).then((response) => {
                    if (response.data.flag) {
                        this.setmeal = response.data.data;
                        return;
                    }
                    this.$message.error(response.data.message);
                });
            }
        },
        mounted() {
            //获取请求路径中的URL参数
            this.setmealId = getUrlParam("id");
            this.orderInfo.setmealId = this.setmealId;
            this.findSetmealDetail();
            axios.get("/address/findAll").then(response => {
                if(response.data.flag){
                    this.addressList = response.data.data;
                }else{
                    this.$message.error(response.data.message);
                }
            })
        }
    });
</script>
<script>
    //日期控件
    var calendar = new datePicker();
    calendar.init({
        'trigger': '.picktime',/*按钮选择器，用于触发弹出插件*/
        'type': 'date',/*模式：date日期；datetime日期时间；time时间；ym年月；*/
        'minDate': getSpecifiedDate(new Date(), 1),/*最小日期*/
        'maxDate': getSpecifiedDate(new Date(), 30),/*最大日期*/
        'onSubmit': function () { /*确认时触发事件*/
            //var theSelectData = calendar.value;
        },
        'onClose': function () { /*取消时触发事件*/
        }
    });
</script>
</body>
</html>